﻿<from class="layui-form layui-form-pane" action="">
    <input type="hidden" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="name" autocomplete="off"
                   placeholder="请输入标名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" pane>
        <label class="layui-form-label">验证方式</label>
        <div class="layui-input-block">
            <input type="radio" name="joinTYpe" value="everybody" title="允许任何人" checked="checked">
            <input type="radio" name="joinTYpe" value="somebody" title="需要身份验证">
        </div>
    </div>

    <div class="layui-form-item" style="text-align: center;">
        <button class="layui-btn" lay-submit="" lay-filter="project-add">确认提交</button>
    </div>
</from>
<script type="text/javascript">
    layui.define(['layer', 'form'], function (exports) {
        var form = layui.form;
        var id = workUtils.get("id");
        form.render(); //这个很重要
        if (id != undefined) {
            $.getJSON("../project/get/" + id, function (data) {
                $("[name='joinTYpe'][value='" + data.joinTYpe + "']").prop("checked", "checked");
                $("[name='name']").val(data.name);
                $("[name='progress']").val(data.progress);
                $("[name='id']").val(data.id);

                form.render(); //这个很重要
            });
        }

        form.on('submit(project-add)', function (data) {
            var index = layer.load(1);
            setTimeout(function () {
                workUtils.ajaxPost('../project/add', data.field, function (result) {
                    layer.close(index);
                    workUtils.msg(result,function () {
                        loadProject();
                    });
                });
            }, 400);
            return false;
        });
    });
</script>